class Node():
    def __init__(self,data,pointer):
        self.data = data
        self.pointer = pointer

def addQueue(data,startPtr,freePtr):
    if freePtr != -1:
        New = freePtr
        freePtr = LinkedList[New].pointer
        LinkedList[New].data = data
        LinkedList[New].pointer = -1
        if startPtr == -1:
            startPtr = New
        else:
            end = startPtr
            while LinkedList[end].pointer != -1:
                end = LinkedList[end].pointer
            LinkedList[end].pointer = New
    return startPtr,freePtr

def popQueue(startPtr,freePtr):
    if startPtr!=-1: #代表不为空
        if LinkedList[startPtr].pointer == -1: #代表只有第一个结点，需要更改start
            LinkedList[startPtr].data = None
            LinkedList[startPtr].pointer = freePtr
            freePtr = startPtr
            startPtr = LinkedList[startPtr].pointer
    else:
        print("the queue is already empty")
    return out,startPtr,freePtr

if __name__ == '__main__':
    LinkedList = [Node(None, 1), Node(None, 2), Node(None, 3), Node(None, 4), Node(None, 5), Node(None, 6),Node(None, 7)]
    freePtr = 0
    startPtr = -1
    for i in range(0,7):                    #test
        startPtr,freePtr = addQueue(int(input("data")),startPtr,freePtr)
    for x in range(0,5):
        data,startPtr,freePtr = popQueue(startPtr,freePtr)
        print(data)
    astartPtr,freePtr = addQueue(55,startPtr,freePtr)
    astartPtr,freePtr = addQueue(66,startPtr,freePtr)
    astartPtr,freePtr = addQueue(77,startPtr,freePtr)
    astartPtr,freePtr = addQueue(88,startPtr,freePtr)
    astartPtr,freePtr = addQueue(99,startPtr,freePtr)
    for y in range(0,7):
        data,startPtr,freePtr = popQueue(startPtr,freePtr)
        print(data)